//
//  MovieShowViewController.m
//  彩虹儿歌
//
//  Created by HelloWorld_L on 15/7/2.
//  Copyright (c) 2015年 HelloBaby. All rights reserved.
//

#import "MovieShowViewController.h"
#import "MovieHomePageVC.h"
#import "MovieLibraryVC.h"
#import "MacroHeader.h"
@interface MovieShowViewController ()
{
    MovieHomePageVC *_homePageVC;
    MovieLibraryVC *_libraryVC;
    BOOL _isShowHomePage;
}


@end

@implementation MovieShowViewController

- (void)dealloc
{
    [_homePageVC release];
    [_libraryVC release];
    [super dealloc];
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.navigationItem.rightBarButtonItem = nil;
}

- (void)viewDidAppear:(BOOL)animated
{
    if (_isShowHomePage == YES) {
        UIImage * image = [[UIImage imageNamed:@"iconfont-chuwukongjian-10"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UIBarButtonItem * switchBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(didClickSwitchButtonItem:)];
        self.tabBarController.navigationItem.rightBarButtonItem = switchBarButtonItem;
        [switchBarButtonItem release];
    } else {
        UIImage * image = [[UIImage imageNamed:@"iconfont-dianying-4"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UIBarButtonItem * switchBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(didClickSwitchButtonItem:)];
        self.tabBarController.navigationItem.rightBarButtonItem = switchBarButtonItem;
        [switchBarButtonItem release];
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    _homePageVC = [[MovieHomePageVC alloc] init];
    _homePageVC.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64);
    [self addChildViewController:_homePageVC];
    
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc] init];
    _libraryVC = [[MovieLibraryVC alloc] initWithCollectionViewLayout:flowLayout];
    _libraryVC.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64);
    [flowLayout release];
    [self addChildViewController:_libraryVC];
    
    
    [self.view addSubview:_homePageVC.view];
    _isShowHomePage = YES;
    
    [_homePageVC release];
    [_libraryVC release];
    
}

- (void)didClickSwitchButtonItem:(UIBarButtonItem *)buttonItem
{
    if (_isShowHomePage == NO) {
        UIImage *image = [[UIImage imageNamed:@"iconfont-chuwukongjian-10"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        buttonItem.image = image;
        
        self.tabBarController.navigationItem.title = @"看儿歌";
        
        [UIView transitionFromView:_libraryVC.view toView:_homePageVC.view duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve completion:nil];
    } else {
        UIImage *image = [[UIImage imageNamed:@"iconfont-dianying-4"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        buttonItem.image = image;
        self.tabBarController.navigationItem.title = @"儿歌视频库";
        
        [UIView transitionFromView:_homePageVC.view toView:_libraryVC.view duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve completion:nil];
    }
    _isShowHomePage = !_isShowHomePage;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
